<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html"/>

</head>
<body class="    fixed-header theme-blue-gradient">
<div id="theme-wrapper">
    <include file="./Application/Home/View/Tpl/header.html"/>

    <div id="page-wrapper" class="container">
        <div class="row">
            <include file="./Application/Home/View/Tpl/menu.html"/>

            <div id="content-wrapper">
                <div class="row">
                    <include file="./Application/Home/View/Tpl/alert.html"/>

                    <div class="row">
                            <div class="col-md-12 ">
                                <div class=" ">
                                    <button class="btn btn-success pull-right" id="addalert">添加预警</button>
                                </div>
                            </div>
                            <BR><BR><BR>
                            <div class="col-md-12 ">
                                <div class="main-box clearfix">
                                    <div class="table-responsive">
                                        <table id="table-example" class="table table-hover"  cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>预警MAC</th>
                                                <th>预警名称</th>
                                            </tr>
                                            </thead>
                                        </table>
                                    </div>
                                </div>
                            </div>

                        </div>
                </div>
                <include file="./Application/Home/View/Tpl/footer.html"/>

            </div>
        </div>
    </div>
</div>

<div class="modal   fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">设置预警</h4>
            </div>
            <div class="modal-body">
                <div class="form-group  ">
                    <label class="control-label" for="alertname"> 预警名称</label>
                    <input type="text" class="form-control"  id="alertname" name="alertname" placeholder="请填写预警名称 ...">
                </div>
                <div class="form-group  ">
                    <label class="control-label" for="mac"> 预警MAC</label>
                    <input type="text" class="form-control" id="mac" name="mac" placeholder="请填写预警MAC ...">
                </div>


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger  btn-lg" id="delete">删 除</button>
                <button type="button" class="btn btn-primary  btn-lg" id="save">保 存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

 <input type="hidden" id="types" name="types" value="edit">
<input type="hidden" id="id" name="id" value="">
</body>
<include file="./Application/Home/View/Tpl/commjs.html"/>
<script src="__PUBLIC__/js/jquery.dataTables.js"></script>
<script src="__PUBLIC__/js/jquery.dataTables.bootstrap.js"></script>


<script type="text/javascript">
    function getmacalert() {
        $.ajax({
            url : "{:U('/Home/scanwifi/getappearmac','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:6000,
            success:function(result){
                console.log(result);
                if(result.status==true){
                    $("#macname").html('');
                    for(var iloop=0; iloop<result.data.length;iloop++){
                        $("#macalert").show();
                        $("#macname").append('<h4 >'+
                            '告警标识：' + result.data[iloop]['alertname'] +
                            ' | mac：' + result.data[iloop]['s_mac']+
                            ' 在' + result.data[iloop]['timedesc'] + '出现！</h4>');
                    }
                }
            },
            error:function(msg){
                console.log(msg);
            }
        });
    }
    setInterval(getmacalert, 10000);

    var table = $('#table-example').DataTable({
        responsive: true,
        "deferRender": true,
        "ajax": {
            "url": "{:U('/Home/Setalert/getdata','',false)}",
            "type": "POST"
        },
        "columns": [
            {"data": "id"},
            {"data": "mac"},
            {"data": "alertname"}
        ],
        "oLanguage": {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有符合条件的预警信息",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 个预警",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索预警信息:",
            "sUrl": "",
            "sEmptyTable": "没有扫描到任何预警信息",
            "sLoadingRecords": "数据加载中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        }
    });

    $('#table-example tbody').on('click', 'tr', function () {
        var data = table.row(this).data();
        console.log(data);
        $("#mac").val(data['mac']);
        $("#alertname").val(data['alertname']);
        $("#id").val(data['id']);

        $("#types").val('edit');
        $("#delete").show();

        $('#myModal').modal('toggle');
    });
    $("#addalert").click(function () {
        $("#types").val('add');
        $("#mac").val('');
        $("#alertname").val('');
        $("#id").val('');
        $("#delete").hide();
        $('#myModal').modal('toggle');
    });

    $("#save").click(function () {
        if($("#mac").val()=="" || $("#alertname").val()==""){
            alert('请输入预警名称和预警MAC');
            return;
        }
        $.ajax({
            url : "{:U('/Home/setalert/save','',false)}",
            type : "post",
            dataType : "json",
            data: {mac:$('#mac').val(), alertname: $('#alertname').val(), types:$('#types').val(), id:$('#id').val()},
            timeout:6000,
            success:function(result){
                if(result.status==true){

                }
                window.location.reload();
            },
            error:function(msg){
                console.log(msg);
                window.location.reload();
            }
        });
    });

    $("#delete").click(function () {
        $("#types").val('delete');
        $.ajax({
            url : "{:U('/Home/setalert/save','',false)}",
            type : "post",
            dataType : "json",
            data: {mac:$('#mac').val(), alertname: $('#alertname').val(), types:$('#types').val(), id:$('#id').val()},
            timeout:6000,
            success:function(result){
                window.location.reload();
            },
            error:function(msg){
                console.log(msg);
                window.location.reload();
            }
        });
    });



</script>

</html>
